<?php
session_start();

// 检查用户是否已登录
if (!isset($_SESSION['user_id'])) {
    header("Location: login21.php");
    exit;
}

require_once 'department21.php';
require_once 'class21.php';
require_once 'student21.php';
require_once 'teacher21.php';
require_once 'course21.php';
require_once 'score21.php';
require_once 'teaching21.php';

$departmentModel = new Department();
$classModel = new Classes();
$studentModel = new Student();
$teacherModel = new Teacher();
$courseModel = new Course();
$scoreModel = new Score();
$teachingModel = new Teaching();

$departmentCount = count($departmentModel->getDepartments());
$classCount = count($classModel->getClasses());
$studentCount = count($studentModel->getStudents());
$teacherCount = count($teacherModel->getTeachers());
$courseCount = count($courseModel->getCourses());
$scoreCount = count($scoreModel->getScores());
$teachingCount = count($teachingModel->getTeachings());

?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>教学服务系统 - 主页</title>
    <link rel="stylesheet" href="styles.css">
</head>
<body>
    <div class="header">
        <div class="container">
            <h1>教学服务系统</h1>
        </div>
    </div>

    <div class="main-nav">
        <div class="container">
            <ul>
                <li><a href="index.php" class="active">主页</a></li>
                <li><a href="departments21.php">系部管理</a></li>
                <li><a href="classes21.php">班级管理</a></li>
                <li><a href="students21.php">学生管理</a></li>
                <li><a href="teachers21.php">教师管理</a></li>
                <li><a href="courses21.php">课程管理</a></li>
                <li><a href="scores21.php">成绩管理</a></li>
                <li><a href="teachings21.php">授课管理</a></li>
                <li class="logout"><a href="logout21.php">退出登录</a></li>
            </ul>
        </div>
    </div>

    <div class="container">
        <div class="card">
            <div class="card-header">
                <h2 class="card-title">系统概览</h2>
            </div>
            
            <div class="message message-success">
                欢迎回来，<?php echo $_SESSION['username']; ?>！当前系统状态正常。
            </div>
            
            <div class="grid-container">
                <div class="grid-item">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">系部管理</h3>
                        </div>
                        <div class="card-body">
                            <p>系部总数: <?php echo $departmentCount; ?></p>
                            <a href="departments21.php" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
                
                <div class="grid-item">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">班级管理</h3>
                        </div>
                        <div class="card-body">
                            <p>班级总数: <?php echo $classCount; ?></p>
                            <a href="classes21.php" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
                
                <div class="grid-item">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">学生管理</h3>
                        </div>
                        <div class="card-body">
                            <p>学生总数: <?php echo $studentCount; ?></p>
                            <a href="students21.php" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
                
                <div class="grid-item">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">教师管理</h3>
                        </div>
                        <div class="card-body">
                            <p>教师总数: <?php echo $teacherCount; ?></p>
                            <a href="teachers21.php" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
                
                <div class="grid-item">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">课程管理</h3>
                        </div>
                        <div class="card-body">
                            <p>课程总数: <?php echo $courseCount; ?></p>
                            <a href="courses21.php" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
                
                <div class="grid-item">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">成绩管理</h3>
                        </div>
                        <div class="card-body">
                            <p>成绩记录: <?php echo $scoreCount; ?></p>
                            <a href="scores21.php" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
                
                <div class="grid-item">
                    <div class="card">
                        <div class="card-header">
                            <h3 class="card-title">授课管理</h3>
                        </div>
                        <div class="card-body">
                            <p>授课记录: <?php echo $teachingCount; ?></p>
                            <a href="teachings21.php" class="btn btn-primary">查看详情</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <style>
        .grid-container {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
        }
        
        .grid-item {
            flex: 1;
            min-width: 300px;
        }
    </style>
</body>
</html>    